from tortoise import fields
from .base import BaseModel, TimestampMixin


class CustomerUser(BaseModel, TimestampMixin):
    platform = fields.IntField(default=1, description="平台1 小程序 2 IOS 3 Android")
    name = fields.CharField(max_length=20, null=True, description="昵称")
    alias = fields.CharField(max_length=30, null=True, description="姓名")
    phone = fields.CharField(max_length=20, null=True, description="电话", index=True)
    address = fields.CharField(max_length=20, null=True, description="地址")
    password = fields.CharField(max_length=128, null=True, description="密码")
    avatar = fields.CharField(max_length=255, null=True, description="头像")
    card_no = fields.IntField(default=0, description="卡号", index=True)
    birth = fields.CharField(max_length=255, null=True, description="生日")
    sex = fields.IntField(default=0, description="性别1男2女")
    age = fields.IntField(default=0, description="年龄")
    identity = fields.CharField(max_length=255, null=True, description="证件号")
    remark = fields.TextField(default="", description="备注", null=True)
    is_active = fields.BooleanField(default=True, description="是否激活")
    is_user = fields.BooleanField(default=False, description="是否设为员工")
    user_id = fields.IntField(default=0, description="系统用户")
    friend_phone = fields.CharField(max_length=20, null=True, description="挚友电话", index=True)
    last_login = fields.DatetimeField(null=True, description="最后登录时间")
    role_id = fields.IntField(default=1, description="角色")
    parent = fields.ForeignKeyField('models.CustomerUser', related_name='customer_parent', null=True,
                                    on_delete=fields.NO_ACTION)
    open_id = fields.CharField(max_length=255, null=True, description="微信openid")
    money_deposit = fields.DecimalField(default=0, max_digits=10, decimal_places=2, description="储值金余额")
    money_integral = fields.DecimalField(default=0, max_digits=10, decimal_places=2, description="积分余额")
    money_coupons = fields.DecimalField(default=0, max_digits=10, decimal_places=2, description="优惠券余额")
    money_commission = fields.DecimalField(default=0, max_digits=10, decimal_places=2, description="佣金余额")
    level_integral = fields.DecimalField(default=0, max_digits=10, decimal_places=2, description="等级积分")

    class Meta:
        table = "customer_list"


class CustomerLevel(BaseModel, TimestampMixin):
    name = fields.CharField(max_length=20, null=True, description="等级名称", index=True)
    value = fields.IntField(max_length=10, default=0, description="等级值")
    level_integral = fields.IntField(default=0,max_length=10, description="升级积分")

    class Meta:
        table = "customer_level"


class CustomerGrow(BaseModel, TimestampMixin):
    name = fields.CharField(max_length=20, null=True, description="模板名称", index=True)
    type = fields.IntField(default=1, description="1固定比例，固定金额")
    routers = fields.JSONField(null=True, description="模板规则json")

    class Meta:
        table = "customer_grow"


class CustomerShare(BaseModel, TimestampMixin):
    user_id = fields.IntField(default=0, description="分享人")
    share_url = fields.CharField(max_length=255, null=True, description="分享链接")
    click_time = fields.IntField(default=0, description="阅读次数")

    class Meta:
        table = "customer_share"
